package com.swotxu.firstribbonclient;

import com.netflix.loadbalancer.BaseLoadBalancer;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;

import java.util.ArrayList;
import java.util.List;

/**
 * @Date: 2020/7/12 15:43
 * @Author: swotXu
 */
public class ChoseServerTest {

    public static void main(String[] args) {
        // 创建负载均衡器
        BaseLoadBalancer balancer = new BaseLoadBalancer();
        //添加服务器列表
        List<Server> servers = new ArrayList<Server>();
        servers.add(new Server("localhost", 8081));
        servers.add(new Server("localhost", 8082));
        balancer.addServers(servers);
        // 进行6次服务器选择
        for (int i = 0; i < 6; i++) {
            Server server = balancer.chooseServer(null);
            System.out.println(server);
        }
    }
}
